with open("specs.csv", mode="r", encoding="utf-8") as file:
    lines = [line.rstrip().split(",") for line in file]

def parse_percentage(string):
    if (string == "–"):
        return "0.0f"
    
    print(string)
    assert(string[-1] == "%")
    return str(float(string.strip("%")) / 100.0) + "f"

def parse_int(str):
    if (str == "–"):
        return "0"
    
    return str

def write_field(file, line):
    file.write("        ." + line + ",\n")

with open("out.txt", "w") as file:
    file.write("LevelSpecs LEVEL_SPECS[21] = {\n")
    for row in lines:
        file.write("    {\n")

        write_field(file, "bonus = BONUS_" + row[1].upper())
        write_field(file, "player_speed = " + parse_percentage(row[3]))
        write_field(file, "ghost_speed = " + parse_percentage(row[5]))
        write_field(file, "ghost_tunnel_speed = " + parse_percentage(row[6]))
        write_field(file, "elroy1_dots = " + parse_int(row[7]))
        write_field(file, "elroy1_speed = " + parse_percentage(row[8]))
        write_field(file, "elroy2_dots = " + parse_int(row[9]))
        write_field(file, "elroy2_speed = " + parse_percentage(row[10]))
        write_field(file, "player_power_speed = " + parse_percentage(row[11]))
        write_field(file, "frightened_speed = " + parse_percentage(row[13]))
        write_field(file, "fright_secs = " + parse_int(row[14]))
        write_field(file, "flash_count = " + parse_int(row[15]))
        file.write("    },\n")

#for line in lines:
#    print(line[0])